package com.api.shopapi.mapper;

import com.api.shopapi.entity.AskAnswerName;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface AskAnswerNameMapper {

    @Insert("insert into ask_answer_name " +
            "(" +
            "AskAnswerNameCode," +
            "Name," +
            "GovernmentCode,"+
            "CommandCenterCode,"+
            "CreateTime,"+
            "Type,"+
            "Status"+
            ") " +
            "values " +
            "(" +
            "#{askAnswerName.AskAnswerNameCode}," +
            "#{askAnswerName.Name}," +
            "#{askAnswerName.GovernmentCode}," +
            "#{askAnswerName.CommandCenterCode}," +
            "#{askAnswerName.CreateTime}," +
            "#{askAnswerName.Type}," +
            "#{askAnswerName.Status}" +
            ")" )
    int insert(@Param("askAnswerName") AskAnswerName askAnswerName);


    @Delete("delete from ask_answer_name where askAnswerNameCode=#{askAnswerNameCode}")
    int delete(@Param("askAnswerNameCode") String askAnswerNameCode);


    @Update("update ask_answer_name set " +
            " Status=#{askAnswerName.Status}," +
            " Type=#{askAnswerName.Type}," +
            " Name=#{askAnswerName.Name}" +
            " where askAnswerNameCode=#{askAnswerName.askAnswerNameCode}")
    int update(@Param("askAnswerName") AskAnswerName askAnswerName);


    @Select("select * from ask_answer_name where askAnswerNameCode=#{askAnswerNameCode} limit 1")
    AskAnswerName getByAskAnswerNameCode(@Param("askAnswerNameCode") String askAnswerNameCode);


    @Select("select * from ask_answer_name where commandCenterCode=#{commandCenterCode} and Status = 1 order by createTime desc")
    List<AskAnswerName> listByCommandCenterCode(@Param("commandCenterCode") String commandCenterCode);


    @Select("select * from ask_answer_name" +
            " where governmentCode=#{governmentCode}" +
            " and Status = 1" +
            " and type=#{type}" +
            " order by createTime desc")
    List<AskAnswerName> listByGovCodeType(@Param("governmentCode") String governmentCode,
                                          @Param("type") String type);


}
